package com.itheima.reggie.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 线程存数据 保存当前登录用户id
 */
@Component
@Slf4j
public class ThreadData {
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<Long>();

    //存
    public static void setId(Long id) {
        long id1 = Thread.currentThread().getId();
        log.info("{}线程存数据...", id1);
        threadLocal.set(id);
    }

    //取
    public static Long getId() {
        long id = Thread.currentThread().getId();
        log.info("{}线程取数据...", id);
        return threadLocal.get();
    }
}
